<template>
  <div class="password">
    <!-- 修改密码弹出框 -->
    <el-dialog
      title="修改密码"
      :visible.sync="changePassword"
      width="675px"
      :modal-append-to-body="true"
      :append-to-body="false"
      center
    >
      <el-form ref="resetForm" :model="resetForm" :rules="resetFormRules" label-position="left">
        <el-form-item label="输入新密码" prop="newpwd" :label-width="formLabelWidth">
          <el-input
            v-model="resetForm.newpwd"
            type="password"
            autocomplete="off"
            placeholder="密码长度8~16位，数字、字母、字符至少包含两种"
          />
        </el-form-item>
        <el-form-item label="重新输入密码" prop="renewpwd" :label-width="formLabelWidth">
          <el-input
            v-model="resetForm.renewpwd"
            type="password"
            autocomplete="off"
            placeholder="重复新密码"
          />
        </el-form-item>

        <el-form-item label="输入验证码" prop="code" :label-width="formLabelWidth">
          <el-input
            v-model="resetForm.code"
            autocomplete="off"
            placeholder="请数入验证码"
          />
        </el-form-item>
        <el-button
          style="left: 513px;
            position: relative;
            top: -62px;"
        >
          获取验证码
        </el-button>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="changePassword = false; Password = true ">确认修改</el-button>
        <el-button @click="changePassword = false">返 回</el-button>
      </span>
    </el-dialog>
    <!-- /修改密码弹出框 -->

    <!-- 修改密码完毕弹出框 -->
    <div class="pwd">
      <el-dialog
        :visible.sync="Password"
        width="670px"
        center
        style="text-agin:content"
      >
        <span>
          <i class="iconfont iconmerchants_icon_dui" />
          <p
            style="
            font-size:22px;
            line-height:42px;
            color:rgba(51,51,51,1);
            "
          >密码修改成功！请重新登陆</p>
        </span>
        <span slot="footer" class="dialog-footer">
          <el-button type="primary" @click="Password = false">重新登陆</el-button>
        </span>
      </el-dialog>
    </div>
  </div>
</template>

<script>
export default {
  name: 'Password',
  data() {
    var validatePass = (rule, value, callback) => {
      if (!value) {
        callback(new Error('请输入新密码'))
      } else if (value.toString().length < 8 || value.toString().length > 18) {
        callback(new Error('密码长度为8 - 18个字符'))
      } else {
        callback()
      }
    }
    var validatePass2 = (rule, value, callback) => {
      if (value === '') {
        callback(new Error('请再次输入密码'))
      } else if (value !== this.resetForm.newpwd) {
        callback(new Error('两次输入密码不一致!'))
      } else {
        callback()
      }
    }
    return {
      resetForm: {
        newpwd: '',
        renewpwd: '',
        code: ''
      },
      resetFormRules: {
        newpwd: [
          { required: true, validator: validatePass, trigger: 'blur' }
        ],
        renewpwd: [
          { required: true, validator: validatePass2, trigger: 'blur' }
        ]
      },
      changePassword: false,
      Password: false,
      formLabelWidth: '120px'

    }
  },
  methods: {
    showPassword() {
      this.changePassword = true
    }
  }
}
</script>

<style lang='scss' scoped>
.password{
  .el-dialog__body{
    text-align: center;
    span{
      .iconfont{
        font-size: 65px;
      }
    }

  }
  .el-dialog__footer{
    .el-button{
      width:170px;
      height:42px;
      background:rgba(65,122,239,1);
      border-radius:4px;
    }
    .el-button:nth-child(2) {
      width:170px;
      height:42px;
      // border:1px solid rgba(219,219,219,1);
      background: #fff;
      border-radius:4px;
    }
  }
}
</style>
